﻿
namespace QuizApp.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the quizdbEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class QuizDomainService : LinqToEntitiesDomainService<quizdbEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Materia' query.
        public IQueryable<Materia> GetMateria()
        {
            return this.ObjectContext.Materia;
        }


        public IQueryable<Materia> GetMateriaTree()
        {
            return this.ObjectContext.Materia.Include("topico.subtopico");
        }



        public void InsertMateria(Materia materia)
        {
            if ((materia.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(materia, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Materia.AddObject(materia);
            }
        }

        public void UpdateMateria(Materia currentMateria)
        {
            this.ObjectContext.Materia.AttachAsModified(currentMateria, this.ChangeSet.GetOriginal(currentMateria));
        }

        public void DeleteMateria(Materia materia)
        {
            if ((materia.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(materia, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Materia.Attach(materia);
                this.ObjectContext.Materia.DeleteObject(materia);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Prova' query.
        public IQueryable<Prova> GetProva()
        {
            return this.ObjectContext.Prova;
        }

        public void InsertProva(Prova prova)
        {
            if ((prova.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(prova, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Prova.AddObject(prova);
            }
        }

        public void UpdateProva(Prova currentProva)
        {
            this.ObjectContext.Prova.AttachAsModified(currentProva, this.ChangeSet.GetOriginal(currentProva));
        }

        public void DeleteProva(Prova prova)
        {
            if ((prova.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(prova, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Prova.Attach(prova);
                this.ObjectContext.Prova.DeleteObject(prova);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ProvaQuestao' query.
        public IQueryable<ProvaQuestao> GetProvaQuestao()
        {
            return this.ObjectContext.ProvaQuestao;
        }

        public void InsertProvaQuestao(ProvaQuestao provaQuestao)
        {
            if ((provaQuestao.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(provaQuestao, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ProvaQuestao.AddObject(provaQuestao);
            }
        }

        public void UpdateProvaQuestao(ProvaQuestao currentProvaQuestao)
        {
            this.ObjectContext.ProvaQuestao.AttachAsModified(currentProvaQuestao, this.ChangeSet.GetOriginal(currentProvaQuestao));
        }

        public void DeleteProvaQuestao(ProvaQuestao provaQuestao)
        {
            if ((provaQuestao.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(provaQuestao, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.ProvaQuestao.Attach(provaQuestao);
                this.ObjectContext.ProvaQuestao.DeleteObject(provaQuestao);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Questao' query.
        public IQueryable<Questao> GetQuestao()
        {
            return this.ObjectContext.Questao;
        }

        public void InsertQuestao(Questao questao)
        {
            if ((questao.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questao, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Questao.AddObject(questao);
            }
        }

        public void UpdateQuestao(Questao currentQuestao)
        {
            this.ObjectContext.Questao.AttachAsModified(currentQuestao, this.ChangeSet.GetOriginal(currentQuestao));
        }

        public void DeleteQuestao(Questao questao)
        {
            if ((questao.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questao, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Questao.Attach(questao);
                this.ObjectContext.Questao.DeleteObject(questao);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'QuestaoAlternativa' query.
        public IQueryable<QuestaoAlternativa> GetQuestaoAlternativa()
        {
            return this.ObjectContext.QuestaoAlternativa;
        }

        public void InsertQuestaoAlternativa(QuestaoAlternativa questaoAlternativa)
        {
            if ((questaoAlternativa.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoAlternativa, EntityState.Added);
            }
            else
            {
                this.ObjectContext.QuestaoAlternativa.AddObject(questaoAlternativa);
            }
        }

        public void UpdateQuestaoAlternativa(QuestaoAlternativa currentQuestaoAlternativa)
        {
            this.ObjectContext.QuestaoAlternativa.AttachAsModified(currentQuestaoAlternativa, this.ChangeSet.GetOriginal(currentQuestaoAlternativa));
        }

        public void DeleteQuestaoAlternativa(QuestaoAlternativa questaoAlternativa)
        {
            if ((questaoAlternativa.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoAlternativa, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.QuestaoAlternativa.Attach(questaoAlternativa);
                this.ObjectContext.QuestaoAlternativa.DeleteObject(questaoAlternativa);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'QuestaoSimples' query.
        public IQueryable<QuestaoSimples> GetQuestaoSimples()
        {
            return this.ObjectContext.QuestaoSimples;
        }

        public void InsertQuestaoSimples(QuestaoSimples questaoSimples)
        {
            if ((questaoSimples.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoSimples, EntityState.Added);
            }
            else
            {
                this.ObjectContext.QuestaoSimples.AddObject(questaoSimples);
            }
        }

        public void UpdateQuestaoSimples(QuestaoSimples currentQuestaoSimples)
        {
            this.ObjectContext.QuestaoSimples.AttachAsModified(currentQuestaoSimples, this.ChangeSet.GetOriginal(currentQuestaoSimples));
        }

        public void DeleteQuestaoSimples(QuestaoSimples questaoSimples)
        {
            if ((questaoSimples.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoSimples, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.QuestaoSimples.Attach(questaoSimples);
                this.ObjectContext.QuestaoSimples.DeleteObject(questaoSimples);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'QuestaoSimplesView' query.
        public IQueryable<QuestaoSimplesView> GetQuestaoSimplesView()
        {
            return this.ObjectContext.QuestaoSimplesView;
        }

        public void InsertQuestaoSimplesView(QuestaoSimplesView questaoSimplesView)
        {
            if ((questaoSimplesView.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoSimplesView, EntityState.Added);
            }
            else
            {
                this.ObjectContext.QuestaoSimplesView.AddObject(questaoSimplesView);
            }
        }

        public void UpdateQuestaoSimplesView(QuestaoSimplesView currentQuestaoSimplesView)
        {
            this.ObjectContext.QuestaoSimplesView.AttachAsModified(currentQuestaoSimplesView, this.ChangeSet.GetOriginal(currentQuestaoSimplesView));
        }

        public void DeleteQuestaoSimplesView(QuestaoSimplesView questaoSimplesView)
        {
            if ((questaoSimplesView.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(questaoSimplesView, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.QuestaoSimplesView.Attach(questaoSimplesView);
                this.ObjectContext.QuestaoSimplesView.DeleteObject(questaoSimplesView);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'SubTopico' query.
        public IQueryable<SubTopico> GetSubTopico()
        {
            return this.ObjectContext.SubTopico;
        }

        public void InsertSubTopico(SubTopico subTopico)
        {
            if ((subTopico.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(subTopico, EntityState.Added);
            }
            else
            {
                this.ObjectContext.SubTopico.AddObject(subTopico);
            }
        }

        public void UpdateSubTopico(SubTopico currentSubTopico)
        {
            this.ObjectContext.SubTopico.AttachAsModified(currentSubTopico, this.ChangeSet.GetOriginal(currentSubTopico));
        }

        public void DeleteSubTopico(SubTopico subTopico)
        {
            if ((subTopico.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(subTopico, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.SubTopico.Attach(subTopico);
                this.ObjectContext.SubTopico.DeleteObject(subTopico);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Topico' query.
        public IQueryable<Topico> GetTopico()
        {
            return this.ObjectContext.Topico;
        }

        public void InsertTopico(Topico topico)
        {
            if ((topico.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(topico, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Topico.AddObject(topico);
            }
        }

        public void UpdateTopico(Topico currentTopico)
        {
            this.ObjectContext.Topico.AttachAsModified(currentTopico, this.ChangeSet.GetOriginal(currentTopico));
        }

        public void DeleteTopico(Topico topico)
        {
            if ((topico.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(topico, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Topico.Attach(topico);
                this.ObjectContext.Topico.DeleteObject(topico);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Usuario' query.
        public IQueryable<Usuario> GetUsuario()
        {
            return this.ObjectContext.Usuario;
        }

        public void InsertUsuario(Usuario usuario)
        {
            if ((usuario.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(usuario, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Usuario.AddObject(usuario);
            }
        }

        public void UpdateUsuario(Usuario currentUsuario)
        {
            this.ObjectContext.Usuario.AttachAsModified(currentUsuario, this.ChangeSet.GetOriginal(currentUsuario));
        }

        public void DeleteUsuario(Usuario usuario)
        {
            if ((usuario.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(usuario, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Usuario.Attach(usuario);
                this.ObjectContext.Usuario.DeleteObject(usuario);
            }
        }
    }
}


